<!DOCTYPE html>
<html>
<head>
    <title>Interval Example 2</title>
</head>
<body>
    <script type="text/javascript">

        var num = 0;
        var max = 10;
        var intervalId = null;
        
        function incrementNumber() {
            num++;
        
            //if the max has been reached, cancel all pending executions
            if (num == max) {
                clearInterval(intervalId);
                alert("Done");
            }
        }
        
        intervalId = setInterval(incrementNumber, 500);


    </script>
</body>
</html>
